home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / coding / cpp / verify.cpp < prev    next >
C/C++ Source or Header  |  1995-03-23  |  1KB  |  54 lines

  1. /*
  2.  * Turbo Vision example of a modified TInputLine that parses input as it
  3.  * is entered.  This line allows only a range of characters to be passed,
  4.  * the range specified in the constructor and defaulting to numeric digits
  5.  * '0'-'9'.
  6.  */
  7.  
  8.   ------------------------------------------------------------------------
  9.    The following example routines have been provided by the Technical
  10.    Support staff at Borland International.  They are provided as a
  11.    courtesy and not as part of a Borland product, and as such, are
  12.    provided without the assurance of technical support or any specific
  13.    guarantees.
  14.  
  15.   ========================================================================
  16.     Copyright (c) 1991 by Borland International
  17.     All Rights Reserved.
  18.  
  19.  
  20.  
  21. #define Uses_TEvent
  22. #define Uses_TInputLine
  23. #include <tv.h>
  24.  
  25. #include <ctype.h>
  26. #pragma hdrstop
  27.  
  28. class TBitLine : public TInputLine
  29. {
  30.  
  31. public:
  32.  
  33.     TBitLine(TRect& bounds, int aMaxLen, char low = '0', char high = '9') :
  34.         TInputLine(bounds, aMaxLen)
  35.     {
  36.         lowDigit = low; highDigit = high;
  37.     }
  38.     virtual void handleEvent(TEvent& event);
  39.  
  40. private:
  41.  
  42.     char lowDigit, highDigit;
  43.  
  44. };
  45.  
  46. void TBitLine::handleEvent(TEvent& event)
  47. {
  48.     char key = event.keyDown.charScan.charCode;
  49.  
  50.     if( !(event.what == evKeyboard && isprint(key) &&
  51.           (key < lowDigit || key > highDigit)) )
  52.         TInputLine::handleEvent(event);
  53. }
  54.